package com.wcgksoft.controller;

import com.wcgksoft.entity.system.EnterpriseProject;
import com.wcgksoft.entity.system.Government;
import com.wcgksoft.entity.system.SysUser;
import com.wcgksoft.service.EnterpriseProjectService;
import com.wcgksoft.service.system.GovernmentService;
import com.wcgksoft.service.system.UserService;
import org.apache.shiro.SecurityUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class indexController {

  @Autowired
  private UserService userService;
  @Autowired
  private EnterpriseProjectService enterpriseProjectService;
  @Autowired
  private GovernmentService governmentService;
  /*@Cacheable(value = "admin")*/
  @GetMapping("/admin")
  public ModelAndView test(HttpServletRequest req) {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("index");
//    SysUser sysUser = (SysUser) SecurityUtils.getSubject().getSession().getAttribute("om_user");
//    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(EnterpriseProject.class);
//    detachedCriteria.add(Restrictions.eq("enterprise", sysUser.getEnterprise()));
//    detachedCriteria.add(Restrictions.eq("parentId", -1));
//    List<EnterpriseProject> enterpriseProjectList = enterpriseProjectService.findByConditions(detachedCriteria);
//    req.getSession().setAttribute("enterprise", enterpriseProjectList);
//    if (sysUser.getSysRole().getSysRoleCode().getRole_number().equals("construction")) {
//      EnterpriseProject id1 = enterpriseProjectService.findById(sysUser.getAreaid());
//      req.getSession().setAttribute("area", id1);
//    }
//    if (sysUser.getSysRole().getSysRoleCode().getRole_number().equals("government")) {
//      Government id1 = governmentService.findById(sysUser.getGov_id());
//      req.getSession().setAttribute("goventerpriselist",id1.getEnterprise());
//    }
    List<SysUser> l = userService.findAll(SysUser.class);
    modelAndView.addObject("msg", l);

    /*java echarts 封装演示*/
/*        String[] s ={"1月","2月","3","4","5","6","7","8","9","10","11","12"};
        List<ChartsBarDataBean> beans = new ArrayList<>();
            ChartsBarDataBean dataBean = new ChartsBarDataBean();
            dataBean.setData(new String[]{"100","200","100","300","200","100","100","200","100","300","200","100"});
            dataBean.setName("巡查次数");
            beans.add(dataBean);

        JSONObject json= ChartsFactory.createBar("各专业问题",12,"月",
                s,"次","次",beans);
        req.getSession().setAttribute("ringJson", json);*/
    // req.setAttribute("msg", "SUCCESS");
    return modelAndView;//返回 /WEB-INF/view 下的 login.html
  }


  @RequestMapping("/cs")
  public String get(HttpServletRequest req) {
    return "template/goodslist";
  }

  @RequestMapping("/ts")
  public String ser(HttpServletRequest req) {
    return "test";
  }
}
